|
|
|
|
|
|
|
Place the picture box on your form as you would any other control. When you select a size for your viewport, keep in mind that picture box controls may have borders. To take the border into account, you need to examine the control's ScaleWidth and ScaleHeight properties to determine how large your viewport will be. |
|
|
|
|
|
|
|
|
The following code sizes a picture box so that its interior is two inches square. This code uses the picture box's current Width, Height, ScaleWidth, and ScaleHeight properties to determine how much extra space it needs to allow for the control's borders. It assumes the control and its parent use the same ScaleMode. |
|
|
|
 |
|
|
|
|
Dim X As Single
Dim Y As Single
Dim border_wid As Single
Dim border_hgt As Single
Dim wid As Single
Dim hgt As Single
' Find the PictureBox's border sizes. border_wid = picViewport.Width - picViewport.ScaleWidth
border_hgt = picViewport.Height - picViewport.ScaleHeight
wid = 2 * 1440 + border_wid
hgt = 2 * 1440 + border_hgt
' Make the viewport 2 inches square. X = picViewport.Left
Y = picViewport.Top
picViewport.Move X, Y, wid, hgt |
|
|
|
|
|
|
|
|
At this point you have a viewport mapped onto your computer's screen. You still need to create a world window to define the mapping from world coordinates into the viewport. You can accomplish this using the picture box's scale properties as described in Chapter 1, Visual Basics. |
|
|
|
|
|
|
|
|
The ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight values are the same as the coordinates that define the world window. For instance, to map a world window with an upper-left corner (0, 10) and lower-right corner (10, 0) into the viewport as shown in Figure 12.5, you could use the following code. |
|
|
|
 |
|
|
|
|
picViewport.ScaleLeft = 0
picViewport.ScaleTop = 10
picViewport.ScaleWidth = (10 - 0)
picViewport.ScaleHeight = (0 - 10) |
|
|
|
|
|
|
|
|
Now you are ready to draw in world coordinate space. When you use the picture box's line, circle, and point drawing routines, the control's scale properties automatically transform your commands into the viewport's coordinate system. |
|
|
|
|
|
|
|
|
Example program Viewport demonstrates this code. It creates a picture box with an interior viewport area two inches square. It then uses the picture box's scale properties |
|
|
|
|
|